
var express=require("express");
var router = express.Router();
var UploadCtrl=require("../controller/UploadCtrl");
var multer  = require('multer');
var path=require("path");
// var upload = multer({ dest: 'uploads/' })

 var storage = multer.diskStorage({
     //设置上传后文件路径，uploads文件夹会自动创建。
        destination: function (req, file, cb) {
            cb(null, path.resolve(__dirname,'../uploads'))
       }, 
     //给上传文件重命名，获取添加后缀名
      filename: function (req, file, cb) {
          var fileFormat = (file.originalname).split(".");
          cb(null, file.fieldname + '-' + Date.now() + "." + fileFormat[fileFormat.length - 1]);
      }
 });  
     //添加配置文件到muler对象。
     var upload = multer({
          storage: storage
    });
//文件上传
router.post("/",upload.single('file'),UploadCtrl.upload);
module.exports=router;